<?php
namespace Components\Products\First;

class Validation extends \Phalcon\Validation {
	public function execute($data) {
		$result = [];
		$validationMessages = $this -> validate($data);
		if($validationMessages -> valid()) {
			return ['code'=>-1,'message'=>$validationMessages[0]->getMessage()];
		} else {
			return ['code'=>0,'data'=>$data];
		}
	}

	public function addProductsClassId() {
		return $this -> rules('products_class_id',[
			new \Phalcon\Validation\Validator\PresenceOf()
		]);
	}

	public function addName() {
		return $this -> rules('name',[
			new \Phalcon\Validation\Validator\PresenceOf()
		]);
	}

	public function addIsShelf() {
		return $this -> rules('is_shelf',[
			new \Phalcon\Validation\Validator\PresenceOf(),
			new \Phalcon\Validation\Validator\InclusionIn([
				'domain' => [1, 2]
			])
		]);
	}
}
